#include "ThreadPool.hpp"
#include <iostream>
#include <thread>

int sum(int a,int b)
{
    std::this_thread::sleep_for(std::chrono::seconds(2));
    return a + b;
}


int main()
{
    ThreadPool pool;
    pool.start(2);
pool.SubmitTask(sum,20,20);pool.SubmitTask(sum,20,20);pool.SubmitTask(sum,20,20);pool.SubmitTask(sum,20,20);pool.SubmitTask(sum,20,20);
    std::future<int> res = pool.SubmitTask(sum,10,20);
    std::future<int> res2 = pool.SubmitTask(sum,20,20);
    std::future<int> res4 = pool.SubmitTask(sum,20,20);
    std::future<int> res3 = pool.SubmitTask([](int a,int b){return a * 10 + b * 10;},10,20);
    std::cout << res.get() << std::endl;
    std::cout << res2.get() << std::endl;
    std::cout << res3.get() << std::endl;
    std::cout << res4.get() << std::endl;
}





// using ULong = unsigned long long;

// class Myclass : public Task
// {
// public:
//     Myclass(int begin, int end)
//         : begin_(begin), end_(end)
//     {
//     }
//     Any run()
//     {
//         ULong sum = 0;
//         std::this_thread::sleep_for(std::chrono::seconds(2));
//         for (int i = begin_; i <= end_; i++)
//         {
//             sum += i;
//         }
//         return sum;
//     }

// private:
//     int begin_;
//     int end_;
// };
// int main()
// {
//     {
//         ThreadPool thread_pool;
//         thread_pool.SetThreadPoolModel(ThreadPoolModel::MODEL_CACHEED);
//         thread_pool.SetTaskQueMaxThreashhold(20);
//         thread_pool.SetThreadPoolThreadMax(6);
//         thread_pool.start(4);

//         Result res1 = thread_pool.SubmitTask(std::make_shared<Myclass>(1, 100000000));
//         Result res2 = thread_pool.SubmitTask(std::make_shared<Myclass>(100000001, 200000000));
//         Result res3 = thread_pool.SubmitTask(std::make_shared<Myclass>(200000001, 300000000));

//         thread_pool.SubmitTask(std::make_shared<Myclass>(200000001, 300000000));
 

//         ULong sum1 = res1.get().cast_<ULong>();
//         // ULong sum2 = res2.get().cast_<ULong>();
//         // ULong sum3 = res3.get().cast_<ULong>();

//         // std::cout << (sum1 + sum2 + sum3) << std::endl;
//     }
//     std::cout << "exit" << std::endl;
//     getchar();
// }